﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;


namespace FineUI.Examples
{
    public partial class student_update_perInformation : System.Web.UI.Page
    {
        protected void LoadCurrentInformaion()
        {

            string currentS_Id = Session["UserName"].ToString();
            Maticsoft.BLL.Student ST = new Maticsoft.BLL.Student();
            Maticsoft.Model.Student STInform = ST.GetModel(currentS_Id);

            tbxUserName.Text = STInform.S_Id;
            tbxPassword.Text = STInform.S_Password ;
            tbxName.Text=STInform.S_Name;
            tbxSex.Text=STInform.S_Sex;
            tbxContact.Text = STInform.S_Contact;
            tbxEmail.Text=STInform.S_Email;
            tbxDepartment.Text=STInform.S_Department;
        
              
        }

        protected void ExistsPermiss(string P_Id, string P_Status)
        {
            Maticsoft.BLL.Permissions PM = new Maticsoft.BLL.Permissions();
            if (!PM.ExistsPermiss(P_Id, P_Status))
            {
                Response.Redirect("~/user_no_permission.aspx");
            }
            
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
                return;
            }

            ExistsPermiss("S000", "已授权");
            if (!IsPostBack)
            {
                LoadCurrentInformaion();
            }
           
        }

        protected void btnUpdateInfrom_Click(object sender, EventArgs e)
        {
            string currentS_Id = tbxUserName.Text.ToString();
            Maticsoft.BLL.Student ST = new Maticsoft.BLL.Student();
            Maticsoft.Model.Student STInform = ST.GetModel(currentS_Id);

            STInform.S_Password = tbxPassword.Text.ToString();
            STInform.S_Name = tbxName.Text.ToString();
            STInform.S_Sex = tbxSex.Text.ToString();
            STInform.S_Contact = tbxContact.Text.ToString();
            STInform.S_Email = tbxEmail.Text.ToString();
            STInform.S_Department = tbxDepartment.Text.ToString();


            if (!ST.Update(STInform))
            {

                Alert.ShowInTop("修改信息失败！", MessageBoxIcon.Information);
            }
            else
                Alert.ShowInTop("修改成功！", MessageBoxIcon.Information);

            LoadCurrentInformaion();
        }
    }
}